package com.yoga.db;

import java.util.HashMap;
import java.util.Map;

import com.yoga.entity.CardInfo;

public class CardDao extends BaseDao{
	public int addCard(CardInfo card) {
		if (dbHelper.getSession().insert("com.yoga.cardInfoMapper.insertCard", card) > 0) {
			dbHelper.getSession().commit();
			return card.getCardId();
		}
		return -1;
	}

	public Integer getCardIdOfUser(int userId, char type) {
		Map params = new HashMap();
		params.put("userId", userId);
		params.put("type", type);
		return dbHelper.getSession().selectOne("com.yoga.cardInfoMapper.getCardIdOfUser", params);
	}

	public int updateCardInfo(int cardId, char type) {
		int res = -1;
		if(type == 'Y')
			res = dbHelper.getSession().update("com.yoga.cardInfoMapper.updateYearCardInfoByAddOneYear", cardId);
		else if(type == 'T')
			res = dbHelper.getSession().update("com.yoga.cardInfoMapper.updateTimesCardInfo", cardId);
		dbHelper.getSession().commit();
		return res;
	}
}
